package com.ruoyi.gxh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gxh.domain.GxhNetInfo;
import com.ruoyi.gxh.service.IGxhNetInfoService;
import com.ruoyi.gxh.vo.GxhNetInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 网站信息发布Controller
 *
 * @author ruoyi
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/gxh/info")
public class GxhNetInfoController extends BaseController {
    @Autowired
    private IGxhNetInfoService gxhNetInfoService;

    /**
     * 查询网站信息发布列表
     */
    @PreAuthorize("@ss.hasPermi('gxh:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxhNetInfo gxhNetInfo) {
        startPage();
        List<GxhNetInfo> list = gxhNetInfoService.selectGxhNetInfoList(gxhNetInfo);
        return getDataTable(list);
    }

    /**
     * 查询网站信息发布列表
     */
    @PreAuthorize("@ss.hasPermi('gxh:info:list')")
    @PostMapping("/list/{pageno}/{pagesize}")
    public AjaxResult list(@RequestBody GxhNetInfoVo gxhNetInfoVo, @PathVariable Integer pageno, @PathVariable Integer pagesize) {
        IPage<GxhNetInfo> page = gxhNetInfoService.list(gxhNetInfoVo, pageno, pagesize);
        return success(page);
    }

    /**
     * 导出网站信息发布列表
     */
    @PreAuthorize("@ss.hasPermi('gxh:info:export')")
    @Log(title = "网站信息发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxhNetInfo gxhNetInfo) {
        List<GxhNetInfo> list = gxhNetInfoService.selectGxhNetInfoList(gxhNetInfo);
        ExcelUtil<GxhNetInfo> util = new ExcelUtil<>(GxhNetInfo.class);
        util.exportExcel(response, list, "网站信息发布数据");
    }

    /**
     * 获取网站信息发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('gxh:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(gxhNetInfoService.selectGxhNetInfoById(id));
    }

    /**
     * 新增网站信息发布
     */
    @PreAuthorize("@ss.hasPermi('gxh:info:add')")
    @Log(title = "网站信息发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxhNetInfo gxhNetInfo) {
        // 走mybatisplus方法，保证元数据自动填充
        gxhNetInfoService.save(gxhNetInfo);
        return success();
    }

    /**
     * 修改网站信息发布
     */
    @PreAuthorize("@ss.hasPermi('gxh:info:edit')")
    @Log(title = "网站信息发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxhNetInfo gxhNetInfo) {
        return toAjax(gxhNetInfoService.updateGxhNetInfo(gxhNetInfo));
    }

    /**
     * 删除网站信息发布
     */
    @PreAuthorize("@ss.hasPermi('gxh:info:remove')")
    @Log(title = "网站信息发布", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gxhNetInfoService.deleteGxhNetInfoByIds(ids));
    }

    /**
     * 信息更新（是否页面显示）
     *
     * @param id
     * @param isshow
     * @return
     */
    @PreAuthorize("@ss.hasPermi('gxh:info:edit')")
    @Log(title = "网站信息发布", businessType = BusinessType.DELETE)
    @PostMapping("/{id}/{isshow}")
    public AjaxResult changeIsshow(@PathVariable Long id, @PathVariable String isshow) {
        return toAjax(gxhNetInfoService.changeIsshow(id, isshow));
    }


}
